package jee.boot.module.iexp.config;

import jee.boot.common.properties.ProjectConfig;
import jee.boot.common.remote.RemoteEndpoint;
import jee.boot.common.utils.SpringContextHolder;
import jee.boot.entity.websocket.WebsocketMessage;

/**
 * 通知消息助手
 */
public class NoticeHandler {


    /**
     * 定点通知(通知到人)
     * @param sid 用户id
     * @param msg 消息对象
     */
    public static void sendMessage(String sid,Object msg){
        RemoteEndpoint remoteEndpoint = SpringContextHolder.getApplicationContext().getBean(RemoteEndpoint.class);
        ProjectConfig projectConfig = SpringContextHolder.getApplicationContext().getBean(ProjectConfig.class);
        WebsocketMessage message = new WebsocketMessage();
        message.setSid(sid);
        message.setMsg(msg);
        remoteEndpoint.executePost(projectConfig.getOpenMessageServer(), "/websocket/send", message, WebsocketMessage.class);

    }

    /**
     * 广播通知,通知所有人
     * @param msg 消息对象
     */
    public  static void sendMessage(Object msg){
        sendMessage(null,msg);
    }
}
